package com.me.brainlessbirds.actors.survivors.units;

import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Timer.Task;
import com.me.brainlessbirds.Assets;
import com.me.brainlessbirds.actors.GameObject;
import com.me.brainlessbirds.actors.obstacles.Obstacle.ObstacleType;
import com.me.brainlessbirds.actors.skills.BaseAttack;
import com.me.brainlessbirds.actors.survivors.Survivor;
import com.me.brainlessbirds.screens.GameScreen;

public class Engineer extends Survivor
{
	public static final int	COST		= 25;
	public boolean			canRepare	= true;
	public boolean			canBuild	= true;

	public Engineer()
	{
		type = SurvivorType.ENGINEER;
		attack = 1.0f;
		defense = 3.0f;
		life = 4.0f;
		speed = 30.0f;
		incomeValue = 1;
		rgnIdle = new TextureRegion(Assets.get().textureEngineer);
		rgnAtk = new TextureRegion(Assets.get().textureEngineerAtk);

		setSize(64.0f, 64.0f);
		setOrigin(getWidth() / 2, getHeight() / 2);

		BaseAttack _bAttack = new BaseAttack(this.attack, 1f);
		_bAttack.setEffectTaskInit(new Task()
		{

			@Override
			public void run()
			{
				// TODO Auto-generated method stub
				//System.out.println("Base attack of Engineer");
			}
		});
		this.skillMap.put(BaseAttack.class, _bAttack);
	}

	@Override
	public boolean collideLeft(GameObject _go)
	{
		boolean isColliding = super.collideLeft(_go);
		if (isColliding)
		{
			_go.OnHitByEngineer(this);
		}
		return isColliding;
	}

	public void buildObstacle()
	{
		double rand = Math.random();
		if (rand > 0.6)
		{
			GameScreen.get().spawnObstacle(ObstacleType.BUMPER, getX(), GameScreen.get().map.getRow(getY()));
		}
		else if (rand > 0.2)
		{
			GameScreen.get().spawnObstacle(ObstacleType.MINE, getX(), GameScreen.get().map.getRow(getY()));
		}
		else
		{
			GameScreen.get().spawnObstacle(ObstacleType.BARRICADE, getX(), GameScreen.get().map.getRow(getY()));
		}
	}
}
